package cn.faifai.framework.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@Slf4j
public class FileUtils {
    public static String getFileSuffix(String fileName) {
        int index = fileName.lastIndexOf(".");
        if (index > 0) {
            return fileName.substring(index + 1);
        }
        return "";
    }

    public static void createHardLink(String source, String target){
        Path hardLink = Paths.get(target);
        if (Files.exists(hardLink)){
            return;
        }
        Path path = Paths.get(source);
        try {
            Files.createLink(hardLink,path);
        } catch (IOException e) {
            log.error("创建硬链接失败");
            log.error(e.getMessage());
            throw new RuntimeException(e);
        }
    }
}
